<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>开工报审修改</title>
	
	<link rel="stylesheet" type="text/css" href="../../themes/general.css">
	<link rel="stylesheet" type="text/css" href="../../themes/icon.css">
	<link rel="stylesheet" type="text/css" href="../../themes/gray/easyui.css">

	<script type="text/javascript" src="../../scripts/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="../../scripts/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../scripts/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="../../scripts/src/jquery.parser.js"></script>
	<script type="text/javascript" src="../../scripts/general.js"></script>
	<script type="text/javascript" src="../../scripts/sessionExpriation.js"></script>

	<script type="text/javascript">
	$(function() {
		//项目的id作为隐藏值保存在表单中
		var projectId = $.getUrlParam('projectId');
	
		//表单提交的ajax
		$('#new_form').form({
			url : '../../project/addOrUpdateBeginWork.ajax?proId='+projectId,
			onSubmit : function() {						
				recordFileName();
				if ($(this).form('validate')) {
					return true;//验证是否为空
				} else {
					return false;
				}
			},
			success : function(data) {
				var obj = $.parseJSON(data);//将json字符串转换为object对象
				if (obj.success) {
					$.messager.alert('提示', obj.message, 'info', function(){
						location.reload();//强迫浏览器刷新当前页面
					});
				} else {
					$.messager.alert('错误', obj.message, 'error');
				}
			}
		});
		//如果不是第一次填写，则需要填上其他信息
		$.ajax({//文件部分
			url : '../../project/initBeginWorkByProId.ajax',
			type : 'post',
			dataType : 'JSON',
			cache: false,
			data : {
				proId : projectId 
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {	                   
	        },
			success : function(data) {
				$('#projectName').text(data.projectName);//待修改，这里是在页面最开始填入项目名称的
				init_file(data);
			}
		});

		//事件绑定，点击提交就提交表单
		$('#btn_submit').bind('click', function() {
			$("#new_form").submit();
		});

});

	//表单提交时验证 最后上传的那部分
	function recordFileName(){
		var fileNames = document.getElementsByName("fileName");//取得标签名为filename的标签对象
		var fileNameIndex 	= '';
		var fileNameVal 	= '';
		for(var k = 0; k < fileNames.length; k++){			
			var tempFileNameObject 	= 	fileNames[k];
			var currentFileNameId 	= 	tempFileNameObject.id;
			var fileNameTot = document.getElementById(currentFileNameId).value
			if (fileNameTot.length != 0) {fileNameVal  += 	fileNameTot + "&";}		
		}
		//将所有的filename的值以&连接传入fileName_total
		document.getElementById("fileName_total").value = fileNameVal;
	}
	
	function init_file(data){
		var list = data.tFileForm;
		    
		$('.origin').each(function(index,element){
			if (list[index].fileFormFilename == null) {//待修改，原始文件名
		    	$(this).text("未上传");
		    }
		    else{
		    	$(this).text(list[index].fileFormFilename)
		    }
		});
	}
	</script>
</head>

<body>
<form id="new_form" method="post" enctype="multipart/form-data">
	<input type="hidden" name="projectId"   		id="projectId" 	value="" />
	<input type="hidden" name="fileNameTotal" 	id="fileName_total" value="" />	
	<span>子项目名称：</span><span id="projectName"></span>
	<table class="table_new" id="fileInfoTab">
		<tr>
			<td class="td_new_subtitle" colspan="3" ><strong>开工报审</strong></td>
		</tr>
		<tr>
			<td align="center" width="80px"><strong>名称</strong></td>
			<td align="center" width="60px"><strong>上传</strong></td>
			<td align="center" width="150px"><strong>已上传文件名</strong></td>
		</tr>
		<tr>
			<td><input type="text" 	id="fileName1" 		name="fileName" 	value="开工报审表" 	size="50" readonly/></td>
			<td><input type="file" 	id="fileUpload1" 	name="fileUpload1" 	 /></td>
			<td align="center" ><span class="origin"></span></td>
		</tr>
		<tr>
			<td><input type="text" 	id="fileName2" 		name="fileName" 	value="方案报审表" 	size="50" readonly/></td>
			<td><input type="file" 	id="fileUpload2" 	name="fileUpload2" 	 /></td>
			<td align="center" ><span class="origin"></span></td>
		</tr>
	</table>
	</br>
	<table class="table_new">
		<tr>
			<td align="center" width="100%"><a id="btn_submit" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok">确认提交</a></td>
		</tr>
	</table>
	
</form>

</body>
</html>